package com.it.nongchanping.service.impl;

import com.it.nongchanping.entity.Company;
import com.it.nongchanping.mapper.CompanyMapper;
import com.it.nongchanping.service.CompanyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 企业信息服务实现类
 */
@Service
public class CompanyServiceImpl implements CompanyService {
    
    @Autowired
    private CompanyMapper companyMapper;
    
    @Override
    public Company getCompanyInfo() {
        // 我们总是获取第一条记录
        return companyMapper.findFirst();
    }
    
    @Override
    public void saveCompanyInfo(Company company) {
        // 企业信息通常只有一条记录，我们硬编码ID为1
        // 如果存在则更新，不存在则插入
        company.setId(1L); 
        Company existing = companyMapper.findFirst();
        if (existing != null) {
            // 确保我们更新的是同一条记录
            company.setId(existing.getId());
            companyMapper.update(company);
        } else {
            companyMapper.insert(company);
        }
    }
} 